﻿using System.Collections.Generic;
using System.Linq;
using JStore.Core.Entities;
using SpeadFrm.ORM;

namespace JStore.Data.Daos
{
    /// <summary>
    ///
    /// </summary>
    public class RoleMenuDao : BaseDao<RoleMenu>
    {
        public List<RoleMenu> GetListByRoleId(int roleId)
        {
            var sql = Sql.Builder.Where("RoleId = @0", roleId);
            return Query(sql).ToList();
        }

        public void DeleteByRoleId(int roleId)
        {
            var sql = Sql.Builder.Where("RoleId = @0", roleId);
            Delete(sql);
        }

        public List<Menus> GetMenuListByRoleId(int roleId)
        {
            var sql = Sql.Builder
                .Append("SELECT * FROM Menus WHERE MenuId IN (SELECT MenuId FROM RoleMenu WHERE RoleId = @0)", roleId);
            return Query<Menus>(sql).ToList();
        }
    }
}

